' Project must reference "Primavera Portfolio Management Open API Interface"
'
' This is a part of the Primavera Portfiolio Management API examples.
' Copyright 1998, 2020, Oracle and/or its affiliates. All Rights Reserved.
'
' This source code is only intended as a supplement to the
'   Primavera Portfolio Management Enterprise API
' electronic documentation provided with the product.
'
' This source code is compatible with Primavera Portfolio Management 20.0 

'*************************************************
' Get list of values in 'Domains' value list
'*************************************************

Public Sub psPortfoliosValueList_GetValues_Example_1()
    ' Login in to Portfolios
    Dim log As Object
    Set log = New psPortfoliosSecurity
    Dim token As String
    token = log.Login("admin", "Password", 10000)
    ' Note: Never code your Password in your program

    Dim ValueListObj As Object
    Set ValueListObj = New psPortfoliosValueList
    
    ValueListObj.SetSecurity (token)
        
    On Error Resume Next ' since GetValues signifies an error by throwing an exception
    Dim vaValues ()
    vaValues = ValueListObj.GetValues( _
                             "Domains" _
             )
    If Err.Number = 0 Then
        msg = "Total of " & (UBound(vaValues)-LBound(vaValues)+1) & " results:" & Chr(13)


        For serial = LBound(vaValues) To UBound(vaValues)           
            oID = vaValues(serial).ID
            oText = vaValues(serial).Text
            oWeight = vaValues(serial).Weight
			oWeightDouble = vaValues(serial).WeightDouble

            msg = msg & "ID=" & oID & ", "
            msg = msg & "Text=" & oText & ", "
			msg = msg & "Weight=" & oWeight & ", "
            msg = msg & "WeightDouble=" & oWeightDouble & Chr(13)
        Next
        
        Call MsgBox(msg, vbOKOnly, "GetValues result")
      
        ' Release memory obtained while calling GetValues
        ValueListObj.ReleaseValues(vaValues)
    Else
        Result = Str(-Err.Number) ' negate the number to obtain the real error code
        Dim ErrorText As String 
        ErrorText = Err.Description
        MsgBox "Error " & Result & " " & ErrorText
        ' in a real system, the description is only displayed to support personnel, 
        ' not to the user
    EndIf

    ' Release security token (log out)
    log.ReleaseSecurityToken (token)
    
    Set ValueListObj = Nothing

End Sub


